package cdu.xjj.repository.basic;

import cdu.xjj.pojo.entity.basic.Clazz;
import cdu.xjj.pojo.vo.ClazzVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ClazzRepository extends JpaRepository<Clazz, Long> {

    @Query("SELECT new cdu.xjj.pojo.vo.ClazzVO(c.id, " +
            "CASE g.stage " +
            "WHEN 0 THEN CONCAT(g.grade, '年级', c.num, '班') " +
            "WHEN 1 THEN CONCAT('初', g.grade, c.num, '班') " +
            "WHEN 2 THEN CONCAT('高', g.grade, c.num, '班') " +
            "ELSE CONCAT(g.grade, '年级', c.num, '班') END) " +
            "FROM Clazz c " +
            "JOIN Grade g ON c.gradeId = g.id " +
            "WHERE c.schoolId = :schoolId " +
            "AND (:stage IS NULL OR g.stage = :stage) " +
            "AND (:grade IS NULL OR g.grade = :grade)")
    List<ClazzVO> findClassList(@Param("schoolId") Long schoolId,
                                @Param("stage") Integer stage,
                                @Param("grade") Integer grade);








}